package com.xiaoshuidi.cloud.module.member.mq.producer;

import com.xiaoshuidi.cloud.framework.mq.core.bus.AbstractBusProducer;
import com.xiaoshuidi.cloud.module.member.mq.message.VerifyCodeMessage;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageConst;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;

@Slf4j
@Component
public class MemberVerifyCodeProducer extends AbstractBusProducer {
    @Value("${spring.cloud.nacos.discovery.group:DEFAULT_GROUP}")
    private String group;


    @Resource
    private StreamBridge streamBridge;

    public void sendVerifyCodeMessage(Long id, LocalDateTime endTime) {
        VerifyCodeMessage verifyCodeMessage = new VerifyCodeMessage().setId(id).setEndTime(endTime);
        streamBridge.send("memberVerifyCodeConsumer-out-0", MessageBuilder.withPayload(verifyCodeMessage)
                .setHeader("TAGS", group)
                .setHeader(MessageConst.PROPERTY_DELAY_TIME_LEVEL,14).build());

    }


}
